package book.items.item29;

import java.util.HashMap;
import java.util.Map;

public class Favorites {
	
	private Map<Class<?>, Object> favorites = new HashMap<Class<?>, Object>();

	public <T> void putFavirite(Class<T> type, T insance) {
		if(type == null) {
			throw new NullPointerException("type is null");
		}
		favorites.put(type, insance);
	}
	
	public <T> T getFavoriate(Class<T> type) {
		return type.cast(favorites.get(type));
	}
	
	public int size() {
		return favorites.size();
	}

	@Override
	public String toString() {
		return favorites.toString();
	}
}
